home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / PACKET / TFLINK10 / TFLNKSRC / TFPCX.C < prev   
C/C++ Source or Header  |  1996-04-14  |  4KB  |  134 lines

  1. /*
  2.  *-----------------------------------------------------------------------
  3.  *
  4.  * TFLINK - program to make TFPCX TSR running a Baycom modem on a
  5.  * COM port appear as a serial (HOST mode) TNC on a second COM port.
  6.  *
  7.  * tfpcx.c - routines to handle TFPCX low-level i/o
  8.  *
  9.  *-----------------------------------------------------------------------
  10.  */
  11.  
  12. /* standard inclusion files */
  13. #include "tflink.h"
  14.  
  15. /* local definitions */
  16. /* define TFPCX constants and defaults */
  17. #define TFPCX_IDENT        "N5NX"    /* identification string */
  18. #define TFPCX_IDENT_OFFSET    3    /* find ident 3 bytes after INT */
  19. #define TFPCX_INT_REQUEST    0x01    /* character ready? function */
  20. #define TFPCX_INT_READ        0x02    /* character read function */
  21. #define TFPCX_INT_WRITE        0x03    /* character write function */
  22. #define TFPCX_INT_VERSION    0xFE    /* get version function */
  23. #define TFPCX_ERROR        0xFFFF    /* if bad int subfunction used */
  24.  
  25.  
  26. /*-----------------------------------------------------------------------*/
  27. /*
  28.  * verify that tfpcx is installed
  29.  */
  30. bool tfpcx_check()
  31. {
  32.     char far*    tfpcx_ident;    /* TFPCX ident string address */
  33.     int        i;        /* loop counter/index */
  34.  
  35.     /* set up a pointer to the TFPCX ident string */
  36.     tfpcx_ident = (char far*)getvect( tfpcx_interrupt )
  37.             + TFPCX_IDENT_OFFSET;
  38.  
  39.     /* check for the presence of the ident string; for some reason,
  40.        strncmp seems unhappy with char far *tfpcx_ident, so do
  41.        the comparison the hard way */
  42.     for ( i = 0; i < strlen( TFPCX_IDENT ); i++ ) {
  43.         /* if character mismatch then return false */
  44.         if ( *(tfpcx_ident + i) != TFPCX_IDENT[ i ] )
  45.             return ( FALSE );
  46.     }
  47.     return ( TRUE );
  48. }
  49.  
  50.  
  51. /*-----------------------------------------------------------------------*/
  52. /*
  53.  * tfpcx ready routine, to detect if a character is waiting
  54.  */
  55. bool tfpcx_request()
  56. {
  57.     union    REGS inr,outr;    /* registers */
  58.  
  59.     /* ensure TFPCX is still available */
  60.     if (! tfpcx_check() )
  61.         return ( FALSE );
  62.  
  63.     /* see if TFPCX has a character ready to read */
  64.     inr.h.ah = TFPCX_INT_REQUEST;
  65.     int86( tfpcx_interrupt, &inr, &outr );
  66.  
  67.     /* test return value of AL */
  68.     if ( outr.h.al )
  69.         return ( TRUE );
  70.     else
  71.         return ( FALSE );
  72. }
  73.  
  74.  
  75. /*-----------------------------------------------------------------------*/
  76. /*
  77.  * tfpcx read character routine for low-level i/o
  78.  */
  79. u_char tfpcx_readch()
  80. {
  81.     union    REGS inr,outr;    /* registers */
  82.  
  83.     /* ensure TFPCX is still available */
  84.     if (! tfpcx_check() )
  85.         return ( (u_char)0 );
  86.  
  87.     /* read the tfpcx character awaiting read */
  88.     inr.h.ah = TFPCX_INT_READ;
  89.     int86( tfpcx_interrupt, &inr, &outr );
  90.  
  91.     /* return character read */
  92.     return ( (u_char)outr.h.al );
  93. }
  94.  
  95.  
  96. /*-----------------------------------------------------------------------*/
  97. /*
  98.  * tfpcx write character routine for low-level i/o.
  99.  */
  100. void tfpcx_writech( u_char c )
  101. {
  102.     union    REGS inr,outr;    /* registers */
  103.  
  104.     /* ensure TFPCX is still available */
  105.     if (! tfpcx_check() )
  106.         return;
  107.  
  108.     /* set tfpcx function code/data and call interrupt */
  109.     inr.h.ah = TFPCX_INT_WRITE;
  110.     inr.h.al = c;
  111.     int86( tfpcx_interrupt, &inr, &outr );
  112. }
  113.  
  114.  
  115. /*-----------------------------------------------------------------------*/
  116. /*
  117.  * read the tfpcx version numbers, and return as one integer
  118.  */
  119. u_int tfpcx_version()
  120. {
  121.     union    REGS inr,outr;    /* registers */
  122.  
  123.     /* ensure TFPCX is still available */
  124.     if (! tfpcx_check() )
  125.         return ( (u_int)0 );
  126.  
  127.     /* set tfpcx function code and call interrupt */
  128.     inr.h.ah = TFPCX_INT_VERSION;
  129.     int86( tfpcx_interrupt, &inr, &outr );
  130.  
  131.     /* return the version value */
  132.     return ( (u_int)((outr.h.ah << 8) | outr.h.al) );
  133. }
  134.